package com.company.emallbackend.handler;

import com.company.emallbackend.common.Result;
import com.company.emallbackend.exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author hanlijian
 * @create 2022-12-03-20:44
 */
@RestControllerAdvice
@Slf4j
public class BaseExceptionHandler {
    
    @ExceptionHandler(Exception.class)
    public Result error(Exception e){
        log.error("系统异常{}",e.getMessage());
        return Result.error("异常");
    }
    
    @ExceptionHandler(CommonException.class)
    public Result error(CommonException e){
        log.error("自定义异常{}",e);
        return Result.error(e.getMsg()); 
    }
    
}
